package com.lv.utils.simpleTask;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author: Lv_sc
 * Date:     2021/3/26 17:07
 * Description: 简单定时任务，注解使用
 */
@Component
//1.主要用于标记配置类，兼备Component的效果。
@Configuration
// 2.开启定时任务
@EnableScheduling
public class SimpleScheduleTask {

    private final static Logger logger = LoggerFactory.getLogger(SimpleScheduleTask.class);

//    //3.添加定时任务 每五秒执一次
//    @Scheduled(cron = "0/5 * * * * ?")
//    private void simpleTaskA() {
//        logger.error("A执行静态定时任务时间: {}", LocalDateTime.now());
//    }

    //每5秒执一次
    @Scheduled(fixedDelay = 1000 * 3600)
    private void simpleTaskB() {
        logger.info("************8b执行静态定时任务时间: {}", LocalDateTime.now());
    }
}




